﻿using System;
using System.Collections.Generic;

namespace RabbitMQDemo.Producer
{
    class Program
    {
        private static readonly Dictionary<string, Action<string[]>> sMethods = new Dictionary<string, Action<string[]>>()
        {
            { "简单队列", Simple.Send },
            { "工作队列", Worker.Send },
            { "发布订阅-Fanout", Fanout.Send },
            { "路由模式-Direct", Direct.Send },
            { "主题模式-Topic", Topic.Send },
            { "生产者消息确认-事务", Transaction.Send },
            { "生产者消息确认-Confirm", Confirm.Send },
            { "消息持久化", Durable.Send },
            { "消息优先级", Priority.Send },
            { "死信队列", DeadLetter.Send }
        };

        static void Main(string[] args)
        {
            var index = 1;
            foreach (var item in sMethods)
            {
                Console.WriteLine($"{index}：{item.Key}");
                index++;
            }

            var method = GetMethod();
            method.Invoke(args);
        }

        private static Action<string[]> GetMethod()
        {
            var value = GetIndex();

            var index = 0;
            foreach (var item in sMethods)
            {
                if (index == value)
                {
                    return item.Value;
                }

                index++;
            }

            return GetMethod();
        }

        private static int GetIndex()
        {
            Console.WriteLine("请输入要启动的生产者编号：");

            var key = Console.ReadLine();
            if (!int.TryParse(key, out int value) || value <= 0 || value > sMethods.Keys.Count)
            {
                return GetIndex();
            }

            return value - 1;
        }
    }
}
